/**
 * Created by shawn on 17/9/11.
 */
const news = {};
const db = require('../connection/mysql');

// var sql = 'select title,id,url from smobile_new';
news.getnews = (formData)=>{
    var data;
    var where = formData;
    console.log(formData);
    db.query('new','id',where,function (err,result) {
        if(err){
            console.log(err);
            return;
        }
        data = result;
        console.log(data);
        return data;
    });
    return data;
}

news.createNews= (formData) => {
    var data;
    // var obj = {id:11,title:3,url:5};
    db.insert('new',formData,function (err,result){
        if(err){
            console.log(err);
            return;
        }
        data = result;
        console.log(data);
        return data;
    });
}

news.modifyNews = (formData)=> {
    var data;
    var sets = formData;
    // console.log(formData);
    var where = {id:formData.id};
    db.update('new',sets,where,function (err,result){
        if(err){
            console.log(err);
            return;
        }
        data = result;
        console.log(data);
        return data;
    });
}

news.deleteNews = (id)=>{
    var data;
    var params = {id:id};
    db.delete('new',params,function (err,result){
        if(err){
            console.log(err);
            return;
        }
        data = result;
        console.log(data);
        return data;
    });
}

module.exports = news;


